home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / security / Provider$Service.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  8.1 KB  |  345 lines

  1. package java.security;
  2.  
  3. import java.lang.ref.Reference;
  4. import java.lang.ref.WeakReference;
  5. import java.lang.reflect.Constructor;
  6. import java.lang.reflect.InvocationTargetException;
  7. import java.util.ArrayList;
  8. import java.util.Collections;
  9. import java.util.HashMap;
  10. import java.util.List;
  11. import java.util.Map;
  12.  
  13. public class Provider$Service {
  14.    private String type;
  15.    private String algorithm;
  16.    private String className;
  17.    private final Provider provider;
  18.    private List<String> aliases;
  19.    private Map<Provider.UString, String> attributes;
  20.    private volatile Reference<Class> classRef;
  21.    private volatile Boolean hasKeyAttributes;
  22.    private String[] supportedFormats;
  23.    private Class[] supportedClasses;
  24.    private boolean registered;
  25.    private static final Class[] CLASS0 = new Class[0];
  26.  
  27.    private Provider$Service(Provider var1) {
  28.       this.provider = var1;
  29.       this.aliases = Collections.emptyList();
  30.       this.attributes = Collections.emptyMap();
  31.    }
  32.  
  33.    private boolean isValid() {
  34.       return this.type != null && this.algorithm != null && this.className != null;
  35.    }
  36.  
  37.    private void addAlias(String var1) {
  38.       if (this.aliases.isEmpty()) {
  39.          this.aliases = new ArrayList(2);
  40.       }
  41.  
  42.       this.aliases.add(var1);
  43.    }
  44.  
  45.    void addAttribute(String var1, String var2) {
  46.       if (this.attributes.isEmpty()) {
  47.          this.attributes = new HashMap(8);
  48.       }
  49.  
  50.       this.attributes.put(new Provider.UString(var1), var2);
  51.    }
  52.  
  53.    public Provider$Service(Provider var1, String var2, String var3, String var4, List<String> var5, Map<String, String> var6) {
  54.       if (var1 != null && var2 != null && var3 != null && var4 != null) {
  55.          this.provider = var1;
  56.          this.type = Provider.access$900(var2);
  57.          this.algorithm = var3;
  58.          this.className = var4;
  59.          if (var5 == null) {
  60.             this.aliases = Collections.emptyList();
  61.          } else {
  62.             this.aliases = new ArrayList(var5);
  63.          }
  64.  
  65.          if (var6 == null) {
  66.             this.attributes = Collections.emptyMap();
  67.          } else {
  68.             this.attributes = new HashMap();
  69.  
  70.             for(Map.Entry var8 : var6.entrySet()) {
  71.                this.attributes.put(new Provider.UString((String)var8.getKey()), var8.getValue());
  72.             }
  73.          }
  74.  
  75.       } else {
  76.          throw new NullPointerException();
  77.       }
  78.    }
  79.  
  80.    public final String getType() {
  81.       return this.type;
  82.    }
  83.  
  84.    public final String getAlgorithm() {
  85.       return this.algorithm;
  86.    }
  87.  
  88.    public final Provider getProvider() {
  89.       return this.provider;
  90.    }
  91.  
  92.    public final String getClassName() {
  93.       return this.className;
  94.    }
  95.  
  96.    private final List<String> getAliases() {
  97.       return this.aliases;
  98.    }
  99.  
  100.    public final String getAttribute(String var1) {
  101.       if (var1 == null) {
  102.          throw new NullPointerException();
  103.       } else {
  104.          return (String)this.attributes.get(new Provider.UString(var1));
  105.       }
  106.    }
  107.  
  108.    public Object newInstance(Object var1) throws NoSuchAlgorithmException {
  109.       if (!this.registered) {
  110.          if (this.provider.getService(this.type, this.algorithm) != this) {
  111.             throw new NoSuchAlgorithmException("Service not registered with Provider " + this.provider.getName() + ": " + this);
  112.          }
  113.  
  114.          this.registered = true;
  115.       }
  116.  
  117.       try {
  118.          Provider.EngineDescription var2 = (Provider.EngineDescription)Provider.access$1000().get(this.type);
  119.          if (var2 == null) {
  120.             return this.newInstanceGeneric(var1);
  121.          } else if (var2.constructorParameterClassName == null) {
  122.             if (var1 != null) {
  123.                throw new InvalidParameterException("constructorParameter not used with " + this.type + " engines");
  124.             } else {
  125.                Class var9 = this.getImplClass();
  126.                return var9.newInstance();
  127.             }
  128.          } else {
  129.             Class var3 = var2.getConstructorParameterClass();
  130.             if (var1 != null) {
  131.                Class var4 = var1.getClass();
  132.                if (!var3.isAssignableFrom(var4)) {
  133.                   throw new InvalidParameterException("constructorParameter must be instanceof " + var2.constructorParameterClassName.replace('$', '.') + " for engine type " + this.type);
  134.                }
  135.             }
  136.  
  137.             Class var10 = this.getImplClass();
  138.             Constructor var5 = var10.getConstructor(var3);
  139.             return var5.newInstance(var1);
  140.          }
  141.       } catch (NoSuchAlgorithmException var6) {
  142.          throw var6;
  143.       } catch (InvocationTargetException var7) {
  144.          throw new NoSuchAlgorithmException("Error constructing implementation (algorithm: " + this.algorithm + ", provider: " + this.provider.getName() + ", class: " + this.className + ")", var7.getCause());
  145.       } catch (Exception var8) {
  146.          throw new NoSuchAlgorithmException("Error constructing implementation (algorithm: " + this.algorithm + ", provider: " + this.provider.getName() + ", class: " + this.className + ")", var8);
  147.       }
  148.    }
  149.  
  150.    private Class getImplClass() throws NoSuchAlgorithmException {
  151.       try {
  152.          Reference var1 = this.classRef;
  153.          Class var2 = var1 == null ? null : (Class)var1.get();
  154.          if (var2 == null) {
  155.             ClassLoader var3 = this.provider.getClass().getClassLoader();
  156.             if (var3 == null) {
  157.                var2 = Class.forName(this.className);
  158.             } else {
  159.                var2 = var3.loadClass(this.className);
  160.             }
  161.  
  162.             this.classRef = new WeakReference(var2);
  163.          }
  164.  
  165.          return var2;
  166.       } catch (ClassNotFoundException var4) {
  167.          throw new NoSuchAlgorithmException("class configured for " + this.type + "(provider: " + this.provider.getName() + ")" + "cannot be found.", var4);
  168.       }
  169.    }
  170.  
  171.    private Object newInstanceGeneric(Object var1) throws Exception {
  172.       Class var2 = this.getImplClass();
  173.       if (var1 == null) {
  174.          Object var9 = var2.newInstance();
  175.          return var9;
  176.       } else {
  177.          Class var3 = var1.getClass();
  178.          Constructor[] var4 = var2.getConstructors();
  179.  
  180.          for(int var5 = 0; var5 < var4.length; ++var5) {
  181.             Constructor var6 = var4[var5];
  182.             Class[] var7 = var6.getParameterTypes();
  183.             if (var7.length == 1 && var7[0].isAssignableFrom(var3)) {
  184.                Object var8 = var6.newInstance(var1);
  185.                return var8;
  186.             }
  187.          }
  188.  
  189.          throw new NoSuchAlgorithmException("No constructor matching " + var3.getName() + " found in class " + this.className);
  190.       }
  191.    }
  192.  
  193.    public boolean supportsParameter(Object var1) {
  194.       Provider.EngineDescription var2 = (Provider.EngineDescription)Provider.access$1000().get(this.type);
  195.       if (var2 == null) {
  196.          return true;
  197.       } else if (!var2.supportsParameter) {
  198.          throw new InvalidParameterException("supportsParameter() not used with " + this.type + " engines");
  199.       } else if (var1 != null && !(var1 instanceof Key)) {
  200.          throw new InvalidParameterException("Parameter must be instanceof Key for engine " + this.type);
  201.       } else if (!this.hasKeyAttributes()) {
  202.          return true;
  203.       } else if (var1 == null) {
  204.          return false;
  205.       } else {
  206.          Key var3 = (Key)var1;
  207.          if (this.supportsKeyFormat(var3)) {
  208.             return true;
  209.          } else {
  210.             return this.supportsKeyClass(var3);
  211.          }
  212.       }
  213.    }
  214.  
  215.    private boolean hasKeyAttributes() {
  216.       Boolean var1 = this.hasKeyAttributes;
  217.       if (var1 == null) {
  218.          synchronized(this) {
  219.             String var3 = this.getAttribute("SupportedKeyFormats");
  220.             if (var3 != null) {
  221.                this.supportedFormats = var3.split("\\|");
  222.             }
  223.  
  224.             var3 = this.getAttribute("SupportedKeyClasses");
  225.             if (var3 != null) {
  226.                String[] var4 = var3.split("\\|");
  227.                ArrayList var5 = new ArrayList(var4.length);
  228.  
  229.                for(String var9 : var4) {
  230.                   Class var10 = this.getKeyClass(var9);
  231.                   if (var10 != null) {
  232.                      var5.add(var10);
  233.                   }
  234.                }
  235.  
  236.                this.supportedClasses = (Class[])var5.toArray(CLASS0);
  237.             }
  238.  
  239.             boolean var14 = this.supportedFormats != null || this.supportedClasses != null;
  240.             var1 = var14;
  241.             this.hasKeyAttributes = var1;
  242.          }
  243.       }
  244.  
  245.       return var1;
  246.    }
  247.  
  248.    private Class getKeyClass(String var1) {
  249.       try {
  250.          return Class.forName(var1);
  251.       } catch (ClassNotFoundException var4) {
  252.          try {
  253.             ClassLoader var2 = this.provider.getClass().getClassLoader();
  254.             if (var2 != null) {
  255.                return var2.loadClass(var1);
  256.             }
  257.          } catch (ClassNotFoundException var3) {
  258.          }
  259.  
  260.          return null;
  261.       }
  262.    }
  263.  
  264.    private boolean supportsKeyFormat(Key var1) {
  265.       if (this.supportedFormats == null) {
  266.          return false;
  267.       } else {
  268.          String var2 = var1.getFormat();
  269.          if (var2 == null) {
  270.             return false;
  271.          } else {
  272.             for(String var6 : this.supportedFormats) {
  273.                if (var6.equals(var2)) {
  274.                   return true;
  275.                }
  276.             }
  277.  
  278.             return false;
  279.          }
  280.       }
  281.    }
  282.  
  283.    private boolean supportsKeyClass(Key var1) {
  284.       if (this.supportedClasses == null) {
  285.          return false;
  286.       } else {
  287.          Class var2 = var1.getClass();
  288.  
  289.          for(Class var6 : this.supportedClasses) {
  290.             if (var6.isAssignableFrom(var2)) {
  291.                return true;
  292.             }
  293.          }
  294.  
  295.          return false;
  296.       }
  297.    }
  298.  
  299.    public String toString() {
  300.       String var1 = this.aliases.isEmpty() ? "" : "\r\n  aliases: " + this.aliases.toString();
  301.       String var2 = this.attributes.isEmpty() ? "" : "\r\n  attributes: " + this.attributes.toString();
  302.       return this.provider.getName() + ": " + this.type + "." + this.algorithm + " -> " + this.className + var1 + var2 + "\r\n";
  303.    }
  304.  
  305.    // $FF: synthetic method
  306.    static boolean access$000(Provider$Service var0) {
  307.       return var0.isValid();
  308.    }
  309.  
  310.    // $FF: synthetic method
  311.    Provider$Service(Provider var1, Provider.1 var2) {
  312.       this(var1);
  313.    }
  314.  
  315.    // $FF: synthetic method
  316.    static String access$302(Provider$Service var0, String var1) {
  317.       return var0.type = var1;
  318.    }
  319.  
  320.    // $FF: synthetic method
  321.    static String access$402(Provider$Service var0, String var1) {
  322.       return var0.algorithm = var1;
  323.    }
  324.  
  325.    // $FF: synthetic method
  326.    static void access$500(Provider$Service var0, String var1) {
  327.       var0.addAlias(var1);
  328.    }
  329.  
  330.    // $FF: synthetic method
  331.    static String access$602(Provider$Service var0, String var1) {
  332.       return var0.className = var1;
  333.    }
  334.  
  335.    // $FF: synthetic method
  336.    static List access$700(Provider$Service var0) {
  337.       return var0.getAliases();
  338.    }
  339.  
  340.    // $FF: synthetic method
  341.    static Map access$800(Provider$Service var0) {
  342.       return var0.attributes;
  343.    }
  344. }
  345.